package com.ymatou.iapi.livebuyer.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.ProductSyncCounterBean;
import com.ymatou.iapi.livebuyer.service.ProductSyncCounterCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CounterCallService;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.utils.EnvSetup;
/**
*job计数器服务扫秒Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ProductSyncCounter{
	private static ProductSyncCounterBean productsynccounterBean;
	private static ProductSyncCounterCall productsynccounterCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("job计数器服务扫秒Test");
	}

	@Before
	public void caseUp() {
		productsynccounterBean=new ProductSyncCounterBean();
		productsynccounterCall=new ProductSyncCounterCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(productsynccounterCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ProductSyncCounter_001() {
		Logger.start(true,"正确数据，成功");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			
			productsynccounterBean.setLiveId(createlive.getId());
			productsynccounterCall.setData(productsynccounterBean);
			Integer counter = CounterCallService.getSingleValueByLiveId(createlive.getId());
			productsynccounterCall.callService();	
			Integer counter1 = CounterCallService.getSingleValueByLiveId(createlive.getId());
			Logger.verifyEquals(counter+1, counter1, "添加商品之后，计数器+1");			
			Logger.verifyEquals("ok", productsynccounterCall.getReturnData(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}